import TencentCloudChat from '@tencentcloud/chat';
import TIMUploadPlugin from 'tim-upload-plugin';
import TIMProfanityFilterPlugin from 'tim-profanity-filter-plugin';
import {
	genTestUserSig
} from '@/utils/GenerateTestUserSig.js'
var options = {
	SDKAppID: 1600009775, // 接入时需要将0替换为您的即时通信 IM 应用的 SDKAppID
	SECRETKEY: '1cc1769a0fc84fff5e7f48ebc6b19c437a751e016b86993a61202c7002278730',
	EXPIRETIME: '86400',
	userID: '21'
};
// 创建 SDK 实例，`TIM.create()`方法对于同一个 `SDKAppID` 只会返回同一份实例
var chat = TencentCloudChat.create(options); // SDK 实例通常用 chat 表示
chat.setLogLevel(0); // 普通级别，日志量较多，接入时建议使用
// chat.setLogLevel(1); // release 级别，SDK 输出关键信息，生产环境时建议使用
// 注册腾讯云即时通信 IM 上传插件
chat.registerPlugin({
	'tim-upload-plugin': TIMUploadPlugin
});
// 注册腾讯云即时通信 IM 本地审核插件
chat.registerPlugin({
	'tim-profanity-filter-plugin': TIMProfanityFilterPlugin
});

export default {
	namespaced: true,
	state: {
		customStatus: ''
	},
	getters: {

	},
	mutations: {
		// setstate(state, payload) {
		// 	for (let i in payload) {
		// 		for (let j in state) {
		// 			if (i === j) {
		// 				state[j] = payload[i];
		// 			}
		// 		}
		// 	}
		// }
	},
	actions: {
		//设置在线
		setSelfStatus({
			dispatch,
			state
		}, data = '在线') {
			console.log('更改在线状态')
			let promise = chat.setSelfStatus({
				customStatus: data
			});
			promise.then(function(imResponse) {
				console.log(imResponse.data);
				// customStatus - 用户自定义状态
				chat.on(TencentCloudChat.EVENT.USER_STATUS_UPDATED, (event) => {
					state.customStatus = event.data[0].customStatus
				});
			}).catch(function(imError) {
				console.warn('setSelfStatus error:', imError); // 设置用户自己的自定义状态失败的相关信息
			});
		},
	},
}